<?php

namespace App\Http\Controllers\AjaxRequest;
use Illuminate\Http\Request;
use Illuminate\Http\Response;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use Input;
use Redirect;
use App\Comment;
use Session;

class LoginController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return Response
     */

    public function index()
    {
         //echo "1234";
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  Request  $request
     * @return Response
     */

    public function store(Request $request)
    {
             $I_UserName = Input::get('I_UserName');
             $I_PassW = Input::get('I_PassW');
             $json_arr = array("username"=>$I_UserName,"password"=>$I_PassW);
             $o="";
            foreach ($json_arr as $k=>$v)
            {
                 $o.= "$k=".urlencode($v)."&";
            }
           $json_data=substr($o,0,-1);
           $url =  "192.168.0.21:8080/test/user/login";

             $ch = curl_init();
             curl_setopt($ch,CURLOPT_URL,$url); /*获取URL的内容*/
             //do a post
            curl_setopt($ch,CURLOPT_POST,true);
            curl_setopt($ch,CURLOPT_POSTFIELDS,$json_data);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);/*获取的内容不输出*/
            $content = curl_exec($ch);/*输出获取的内容*/
            curl_close($ch);
            $obj = json_decode($content);
           if(isset($obj->id))
            {
                Session::put('user_id','$obj->id');
                Session::save();
                return Redirect::to('useraccount?id='.$obj->id);
            }else{
                return Redirect::back()->withInput()->withErrors('你输入的账户名和密码不匹配，你是否忘记会员名或忘记密码!');

            };
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  Request  $request
     * @param  int  $id
     * @return Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *su
     * @param  int  $id
     * @return Response
     */
    public function destroy($id)
    {
        //
    }
}
?>